import java.util.ArrayDeque;
import java.util.Stack;
//https://leetcode.cn/problems/min-stack/submissions/555441965/
class MinStack {
    Stack<Integer> stackNor;
    Stack<Integer> stackMin;

    public MinStack() {
        stackNor = new Stack<>();
        stackMin = new Stack<>();
    }

    public void push(int val) {
        stackNor.push(val);
        if (stackMin.isEmpty()){
            stackMin.push(val);
        }else {
            int minVal = stackMin.peek();
            if (val <= minVal) {
                stackMin.push(val);
            }
        }
    }

    public void pop() {
        int popVal = stackNor.pop();
        if (popVal == stackMin.peek()) {
            stackMin.pop();
        }
    }

    public int top() {
        return stackNor.peek();
    }

    public int getMin() {
        return stackMin.peek();
    }
}